The Scanner class reads input. Scanner scan = new Scanner(System.in); creates a Scanner that can read from the keyboard.
The following an example of part of a code using the Scanner class: int rockLeesEyeLashes;
double rockLeesWeight;
Scanner scan = new Scanner(System.in);
System.out.print("Enter the number of Rock Lee's eye lashes: ");
rockLeesEyeLashes = scan.nextInt();
System.out.print("Enter Rock Lee's weight: ");
rockLeesWeight = scan.nextDouble();
This fragment of a code stores the input of the number of eyelashes and Rock Lee's weight.
Here's an example of how to use the Scanner class to store words: String rockLeesConfession;
Scanner scan = new Scanner (System.in);
System.out.println("Enter Rock Lee's confession: ");
rockLeesConfession = scan.nextLine();
System.out.println("Rock Lee's confession is: \"" + rockLeesConfession + "\"");
This fragment of a code stores the input of Rock Lee's confession.
Scanner scan = new Scanner(System.in); creates a Scanner that can read from the keyboard.
The following an example of part of a code using the Scanner class:
int rockLeesEyeLashes;
double rockLeesWeight;
Scanner scan = new Scanner(System.in);
System.out.print("Enter the number of Rock Lee's eye lashes: ");
rockLeesEyeLashes = scan.nextInt();
System.out.print("Enter Rock Lee's weight: ");
rockLeesWeight = scan.nextDouble();
This fragment of a code stores the input of the number of eyelashes and Rock Lee's weight.
Here's an example of how to use the Scanner class to store words:
String rockLeesConfession;
Scanner scan = new Scanner (System.in);
System.out.println("Enter Rock Lee's confession: ");
rockLeesConfession = scan.nextLine();
System.out.println("Rock Lee's confession is: \"" + rockLeesConfession + "\"");
This fragment of a code stores the input of Rock Lee's confession.
n